package com.thd.filter;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;

@Component
public class ObjectValueGatewayFilterFactory extends AbstractGatewayFilterFactory<ObjectValueGatewayFilterFactory.Config> {
    @Override
    public GatewayFilter apply(final Config config) {
        return new ObjectValueGatewayFilter(config);
    }

    /**
     * 不要忘记加这个构造方法
     */
    public ObjectValueGatewayFilterFactory() {
        super(Config.class);
    }

    /**
     * 如果在yml中配置的Filter有参数，可以创建下面的Config，配置的时候如下：
     *
     *        filters:
     *            - name: ObjectValue
     *              args:
     *                message: My Custom Message
     *                preLogger: true
     *                postLogger: true
     */
    public static class Config {
        private String message;
        private boolean preLogger;
        private boolean postLogger;

        public Config(){

        }

        public Config(String message, boolean preLogger, boolean postLogger) {
            this.message = message;
            this.preLogger = preLogger;
            this.postLogger = postLogger;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public boolean isPreLogger() {
            return preLogger;
        }

        public void setPreLogger(boolean preLogger) {
            this.preLogger = preLogger;
        }

        public boolean isPostLogger() {
            return postLogger;
        }

        public void setPostLogger(boolean postLogger) {
            this.postLogger = postLogger;
        }
    }
}
